package com.app.megaprosoft.DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class PromotionGiveaways {
	 ResultSet rs = null;
	 SQLiteDBClass myDb;
	 SQLiteDatabase db;
	 Context context;
	 private static final String TABLE_PromotionGiveaways 				= "_PromotionGiveaways";
	 private static final String TABLE_PromotionGiveawayDetails 		= "_PromotionGiveawayDetails";
	 public Context getContext() {
		return context;
	 }
	 public void setContext(Context context) {
			this.context = context;
		}
	
	private String 	OID,
				    UsrOpt,
				    IsActive,
				    IsDeleted,
				    
				    PromotionGName,
					PromotionGDescription,
					PromotionGStartDate,
					PromotionGEndDate,
	
					PromotionGOID,
					ItemOID,
					PromotionGDType;
	
	private String  ParamPromotionGName,
					ParamPromotionGOID,
				    ParamPromotionGDType;
    

	//Get Parameter
	public String getParamPromotionGName() {
		return ParamPromotionGName;
	}

	public void setParamPromotionGName(String paramPromotionGName) {
		ParamPromotionGName = paramPromotionGName;
	}
	
	public String getParamPromotionGOID() {
		return ParamPromotionGOID;
	}

	public void setParamPromotionGOID(String paramPromotionGOID) {
		ParamPromotionGOID = paramPromotionGOID;
	}

	public String getParamPromotionGDType() {
		return ParamPromotionGDType;
	}

	public void setParamPromotionGDType(String paramPromotionGDType) {
		ParamPromotionGDType = paramPromotionGDType;
	}

	//Get Set
	public String getOID() {
		return OID;
	}

	public void setOID(String oID) {
		OID = oID;
	}

	public String getIsActive() {
		return IsActive;
	}

	public void setIsActive(String isActive) {
		IsActive = isActive;
	}

	public String getIsDeleted() {
		return IsDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}

	public String getPromotionGName() {
		return PromotionGName;
	}

	public void setPromotionGName(String promotionGName) {
		PromotionGName = promotionGName;
	}

	public String getPromotionGDescription() {
		return PromotionGDescription;
	}

	public void setPromotionGDescription(String promotionGDescription) {
		PromotionGDescription = promotionGDescription;
	}

	public String getPromotionGStartDate() {
		return PromotionGStartDate;
	}

	public void setPromotionGStartDate(String promotionGStartDate) {
		PromotionGStartDate = promotionGStartDate;
	}

	public String getPromotionGEndDate() {
		return PromotionGEndDate;
	}

	public void setPromotionGEndDate(String promotionGEndDate) {
		PromotionGEndDate = promotionGEndDate;
	}
	
	public String getUsrOpt() {
		return UsrOpt;
	}

	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}
	
	// Detail
	public String getPromotionGOID() {
		return PromotionGOID;
	}

	public void setPromotionGOID(String promotionGOID) {
		PromotionGOID = promotionGOID;
	}

	public String getItemOID() {
		return ItemOID;
	}

	public void setItemOID(String itemOID) {
		ItemOID = itemOID;
	}

	public String getPromotionGDType() {
		return PromotionGDType;
	}

	public void setPromotionGDType(String promotionGDType) {
		PromotionGDType = promotionGDType;
	}

	// Query
	public ResultSet selectPromotionGiveaways() throws Exception {
		 Connect con = new Connect(); 
        String StrSql = "SELECT	* " +
						"FROM 	[dbo].[udfPromotionGiveaways]() " +
						"WHERE 	[IsDeleted] = '0' " ;
        
        if(getParamPromotionGName() != null)
        	StrSql += "AND [PromotionGName] LIKE '%" + getParamPromotionGName() + "%' ";
        
        StrSql += 	"ORDER BY [PromotionGStartDate] ASC";
        
        return con.selectData(StrSql);
    }
	
	// Query Detail
	public ResultSet selectPromotionGiveawayDetails() throws Exception {
		 Connect con = new Connect(); 
        String StrSql = "SELECT	* " +
						"FROM 	[dbo].[udfPromotionGiveawayDetails]() " +
						"WHERE 	[IsDeleted] = '0' " ;
        
        if(getParamPromotionGOID() != null)
        	StrSql += "AND [PromotionGOID] = '" + getParamPromotionGOID() + "' ";
        
        if(getParamPromotionGDType() != null)
        	StrSql += "AND [PromotionGDType] = '" + getParamPromotionGDType() + "' ";
        
        StrSql += 	"ORDER BY [ItemCode] ASC";
        
        return con.selectData(StrSql);
    }
	

	 public void DEFINE_PromotionGiveAway() {
			rs = null;
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			try {
				rs = selectPromotionGiveaways();
				while (rs.next()) {
					ContentValues Val = new ContentValues();
					Val.put("PromotionGOID", rs.getString("OID"));

					Val.put("PromotionGName", rs.getString("PromotionGName"));
					Val.put("PromotionGDescription", rs.getString("PromotionGDescription"));
					Val.put("PromotionGStartDate", rs.getString("PromotionGStartDate"));
					Val.put("PromotionGEndDate", rs.getString("PromotionGEndDate"));
					

					db.insert(TABLE_PromotionGiveaways, null, Val);
				}
				rs.close();
			} catch (Exception e) {
				Log.d("TABLE_PromotionGiveaways", "Create Table not Successfully.");
			}
			Log.d("TABLE_PromotionGiveaways", "Create Table Successfully.");
			db.close();
		}
	 
	 public void DEFINE_PromotionGiveAwayDetail() {
			rs = null;
			myDb = new SQLiteDBClass(getContext());
			db = myDb.getWritableDatabase();

			try {
				rs = selectPromotionGiveawayDetails();
				while (rs.next()) {
					ContentValues Val = new ContentValues();
					Val.put("PromotionGDOID", rs.getString("OID"));

					Val.put("PromotionGOID", rs.getString("PromotionGOID"));
					Val.put("ItemOID", rs.getString("ItemOID"));
					Val.put("PromotionGDType", rs.getString("PromotionGDType"));

				

					db.insert(TABLE_PromotionGiveawayDetails, null, Val);
				}
				rs.close();
			} catch (Exception e) {
				Log.d("TABLE_PromotionGiveawayDetails", "Create Table not Successfully.");
			}
			Log.d("TABLE_PromotionGiveawayDetails", "Create Table Successfully.");
			db.close();
		}
	 
}
